$(function () {
    window['moment-range'].extendMoment(moment);

function hotMapRander(){
    var map = new BMap.Map("hotMap", {enableMapClick: false});          // 创建地图实例
    map.setMapStyle({style: 'midnight'});
    var point = new BMap.Point(120.194145, 30.240854);
    map.centerAndZoom(point, 15);             // 初始化地图，设置中心点坐标和地图级别
    map.enableScrollWheelZoom(); // 允许滚轮缩放
    var hotPoints = []
    $.ajax({
        url: '/deviceStatus/data/list/thermograph/001/byuser',
        async: false,
        success: function (result) {
            hotPoints = result.data;
        }
    });

    if (!isSupportCanvas()) {
        alert('热力图目前只支持有canvas支持的浏览器,您所使用的浏览器不能使用热力图功能~')
    }
    //详细的参数,可以查看heatmap.js的文档 https://github.com/pa7/heatmap.js/blob/master/README.md
    //参数说明如下:
    /* visible 热力图是否显示,默认为true
     * opacity 热力的透明度,1-100
     * radius 势力图的每个点的半径大小
     * gradient  {JSON} 热力图的渐变区间 . gradient如下所示
     *  {
     .2:'rgb(0, 255, 255)',
     .5:'rgb(0, 110, 255)',
     .8:'rgb(100, 0, 255)'
     }
     其中 key 表示插值的位置, 0~1.
     value 为颜色值.
     */
    heatmapOverlay = new BMapLib.HeatmapOverlay({"radius": 20});
    map.addOverlay(heatmapOverlay);
    heatmapOverlay.setDataSet({data: hotPoints, max: 10});
    //加载热力图
    openHeatmap();
    setGradient();
    getBoundary();

    //是否显示热力图
    function openHeatmap() {
        heatmapOverlay.show();
    }

    function closeHeatmap() {
        heatmapOverlay.hide();
    }

    function setGradient() {
        /*格式如下所示:*/
        var gradient1 = {
            0: 'rgb(102, 255, 0)',
            .5: 'rgb(255, 170, 0)',
            1: 'rgb(255, 0, 0)'
        }
        var gradient = {};
        var colors = document.querySelectorAll("input[type='color']");
        colors = [].slice.call(colors, 0);
        console.log(colors)
        colors.forEach(function (ele) {
            console.log(ele)
            gradient[ele.getAttribute("data-key")] = ele.value;
        });
        heatmapOverlay.setOptions({"gradient": gradient1});
    }

    //判断浏览区是否支持canvas
    function isSupportCanvas() {
        var elem = document.createElement('canvas');
        return !!(elem.getContext && elem.getContext('2d'));
    }

//划分行政区域
    function getBoundary() {
        var bdary = new BMap.Boundary();
        bdary.get("杭州上城区", function (rs) {       //获取行政区域
            //map.clearOverlays();        //清除地图覆盖物
            var count = rs.boundaries.length; //行政区域的点有多少个
            if (count === 0) {
                alert('未能获取当前输入行政区域');
                return;
            }
            var pointArray = [];
            for (var i = 0; i < count; i++) {
                var ply = new BMap.Polygon(rs.boundaries[i], {
                    strokeWeight: 2,
                    strokeColor: "#ff855c",
                    fillColor: "rgba(0,0,0,0)"
                }); //建立多边形覆盖物,fillColor:"rgba(0,0,0,0)"
                map.addOverlay(ply);  //添加覆盖物
                pointArray = pointArray.concat(ply.getPath());
            }
            map.setViewport(pointArray);    //调整视野
            //addlabel();
        });
    }
}

    //==========================
    //渲染热力图
    hotMapRander();

//首次渲染七天报警总数
    alarmSumFunc1();

    //	七日报警
    sevenAlarmSumDataRander();

    //响应速度
    speedFunc();

    //三色预警
    earlylist0();

    //		重点关注
    sevenFocusCanvasTime();

//	报警来源柱状图
    alarmSourceCharts1Func();

    //报警来源图表
    alarmSourceCharts();

    //报警总数数量和同比
    var alarmCount = [];
    var alarmPercent = [];
    alarmFunc();

    //报警来源初始化渲染分页

    var fixedPlace = 'all';
    var sourceweekOfday = moment().format('E');//这周的第几天
    var sourceBeginTime = moment().add('days', 1).subtract(sourceweekOfday, 'days').format('YYYY-MM-DD')+' 00:00:00';
    var sourceEndTime = moment().add('days', 7).subtract(sourceweekOfday, 'days').format('YYYY-MM-DD')+' 23:59:59';

    //报警原因
    alarmCauseCharts();

//	报警原因二级模态框
    alarmCauseCharts1Func();

    //报警原因初始化渲染分页
    var alarmReasons = 'all';
    var causeweekOfday = moment().format('E');//这周的第几天
    var causeBeginTime = moment().add('days', 1).subtract(causeweekOfday, 'days').format('YYYY-MM-DD')+' 00:00:00';
    var causeEndTime = moment().add('days', 7).subtract(causeweekOfday, 'days').format('YYYY-MM-DD')+' 23:59:59';

    //===========================
    //关闭报警来源表
    $(".data #alarmSourceModal-close").on('click', function () {
        $(".data #alarmSourceModalBox").modal('hide');
    });
    //开启报警来源模态框
    $(".data .c-bottom #alarmSource").on('click', function () {
        $(".data #alarmSourceModalBox").modal('show');
        sourceRanderListPage(fixedPlace, 1,sourceBeginTime,sourceEndTime);
        sourcePage(fixedPlace,sourceBeginTime,sourceEndTime);
    });
    //报警来源查询下拉框
    $(".data #alarmSourceModal-data").on('click', function () {
        $('.data #alarmSourceModal-dataBox ul').toggle();
        return false;
    });
    $('.data').on('click', function () {
        $('.data #alarmSourceModal-dataBox ul').hide();
    });




    //关闭报警原因表
    $(".data #alarmCauseModal-close").on('click', function () {
        $('#alarmCauseModalBox').modal('hide');
    });
    //开启报警原因模态框
    $(".data .c-bottom #alarmCause").on('click', function () {
        $('#alarmCauseModalBox').modal('show');
        causeRanderListPage(alarmReasons, 1,causeBeginTime,causeEndTime);
        causePage(alarmReasons,causeBeginTime,causeEndTime);
    });
    //报警原因查询下拉框
    $(".data #alarmCauseModal-data").on('click', function () {
        $('.data #alarmCauseModal-dataBox ul').toggle();
        return false;
    });
    $('.data').on('click', function () {
        $('.data #alarmCauseModal-dataBox ul').hide();
    });

    //七日报警弹出框
    $('.data #sevenAlarmCanvas').on('click', function () {
        $('#alarmStatisticsModalBox').modal('show');
        sevenAlarmSumDataModal();
    })
    $('.data #alarmStatisticsModal-close').on('click', function () {
        $('#alarmStatisticsModalBox').modal('hide');
    });

//七日数据统计切换时间按钮
    $('.data .sevenDataBtnBox ul li').on('click', function () {
        $(this).addClass('active').siblings().removeClass('active');
        var index = $(this).index();
        var beginTime;
        var endTime;
        var weekOfday = moment().format('E');//这周的第几天

        if (index == 0) {
            //周一
            beginTime = moment().add('days', 1).subtract(weekOfday, 'days').format('YYYY-MM-DD');
            //周日
            endTime = moment().add('days', 7).subtract(weekOfday, 'days').format('YYYY-MM-DD');
        } else if (index == 1) {
            //月初
            beginTime = moment().startOf('month').format("YYYY-MM-DD");
            //月末
            endTime = moment().endOf('month').format("YYYY-MM-DD");
        } else if (index == 2) {
            var monthDaysArr = nowQuarter();
            beginTime = monthDaysArr[0];
            endTime = monthDaysArr[1];
        }
        beginTime += ' 00:00:00';
        endTime += ' 23:59:59';
        alarmSumFunc(beginTime, endTime);
    });
    function alarmSumFunc(beginTime, endTime) {

        $.ajax({
            url: "/alarm/data/device/getcount?beginTime=" + beginTime + "&endTime=" + endTime + "&alarmTypeCode=1",
            success: function (result) {
                console.log(result.data[0])
                $(".data .c-top .alarmSum i").text(result.data[0])
            }
        });
    }

    function alarmSumFunc1() {
        var weekOfday = moment().format('E');//这周的第几天
        //周一
        beginTime = moment().add('days', 1).subtract(weekOfday, 'days').format('YYYY-MM-DD') + ' 00:00:00';
        //周日
        endTime = moment().add('days', 7).subtract(weekOfday, 'days').format('YYYY-MM-DD') + ' 23:59:59';
        $.ajax({
            url: "/alarm/data/device/getcount?beginTime=" + beginTime + "&endTime=" + endTime + "&alarmTypeCode=1",
            success: function (result) {
                console.log(result.data[0])
                $(".data .c-top .alarmSum i").text(result.data[0])
            }
        });
    }

    /* 点击的时候切换时间段  */
    //------------------------------------------------------------------
    //七日报警弹出框

    //报警来源查询下拉框
    $(".data #alarmStatisticsModal-data").on('click', function () {
        $('.data #alarmStatisticsModal-dataBox ul').toggle();
        return false;
    });
    $('.data').on('click', function () {
        $('.data #alarmStatisticsModal-dataBox ul').hide();
    });
    //本周
    function sevenAlarmSumDataModal(){
        var alarmDateArrX1=[];
        var alarmDateArrY1=[];
        var weekOfday = moment().format('E');//这周的第几天
        var beginTime1 = moment().add('days', 1).subtract(weekOfday, 'days').format('YYYY-MM-DD')+' 00:00:00';
        var endTime1 = moment().add('days', weekOfday).subtract(weekOfday, 'days').format('YYYY-MM-DD')+' 23:59:59';
        var start1 = moment().add('days', 1).subtract(weekOfday, 'days').format('YYYY-MM-DD');
        var end1 = moment().add('days', weekOfday).subtract(weekOfday, 'days').format('YYYY-MM-DD');
        var alarmStatisticsCanva1 = echarts.init(document.getElementById("alarmStatisticsCanva1"));
        var monthAlarmCanvasoption;
        sevenAlarmSumData(alarmDateArrX1,alarmDateArrY1,start1,end1,beginTime1, endTime1,alarmStatisticsCanva1,monthAlarmCanvasoption)
    }
    //点击时间按钮切换对应数据
    $('.data #alarmStatisticsModal-dataBox ul li').on('click', function () {
        var alarmDateArrX1=[];
        var alarmDateArrY1=[];

        var text = $(this).text();
        console.log(text)
        $('.data #alarmStatisticsModal-week').text(text);
        var mydata = $(this).attr('mydata');

        var beginTime1;
        var endTime1;
        var start1;
        var end1;
        if (mydata == "week") {
            var statisticsweekOfday = moment().format('E');//这周的第几天
            start1 = moment().add('days', 1).subtract(statisticsweekOfday, 'days').format('YYYY-MM-DD')+' 00:00:00';
            end1 = moment().add('days', 7).subtract(statisticsweekOfday, 'days').format('YYYY-MM-DD')+' 23:59:59';
            //折线图
            sevenAlarmSumDataModal();
        } else if (mydata == "month") {
            //折线图
            beginTime1 = moment().startOf('month').format("YYYY-MM-DD");
            endTime1 = moment().add('days', 0).format("YYYY-MM-DD");
            start1 = beginTime1+' 00:00:00';
            end1 = endTime1+' 23:59:59';
            var alarmStatisticsCanva1 = echarts.init(document.getElementById("alarmStatisticsCanva1"));
            var monthAlarmCanvasoption;
            sevenAlarmSumData(alarmDateArrX1,alarmDateArrY1,start1,end1,beginTime1, endTime1,alarmStatisticsCanva1,monthAlarmCanvasoption)
        } else if (mydata == "quarter") {
            //折线图
            var monthDaysArr = nowQuarter();
            beginTime1 = monthDaysArr[0];
            endTime1 = moment().add('days', 0).format("YYYY-MM-DD");
            start1 = beginTime1+' 00:00:00';
            end1 = endTime1+' 23:59:59';
            var alarmStatisticsCanva1 = echarts.init(document.getElementById("alarmStatisticsCanva1"));
            var monthAlarmCanvasoption;
            sevenAlarmSumData(alarmDateArrX1,alarmDateArrY1,start1,end1,beginTime1, endTime1,alarmStatisticsCanva1,monthAlarmCanvasoption)
        }
        statisticsBeginTime = start1;
        statisticsEndTime=end1;
        statisticsRanderListPage( 1,statisticsBeginTime,statisticsEndTime);
        statisticsPage(statisticsBeginTime,statisticsEndTime);
    });




    var statisticsweekOfday = moment().format('E');//这周的第几天
    var statisticsBeginTime = moment().add('days', 1).subtract(statisticsweekOfday, 'days').format('YYYY-MM-DD')+' 00:00:00';
    var statisticsEndTime = moment().add('days', 7).subtract(statisticsweekOfday, 'days').format('YYYY-MM-DD')+' 23:59:59';
    statisticsRanderListPage( 1,statisticsBeginTime,statisticsEndTime);
    statisticsPage(statisticsBeginTime,statisticsEndTime);


    //渲染列表数据
    function statisticsRanderListPage(page,beginTime,endTime) {
        $.ajax({
            url:'/paging/dayAlarm/approve?beginTime='+beginTime+'&endTime='+endTime+'&alarmTypeCode=001&deviceTypeId=001&page='+page,
            //url: '/paging/fixedPlace/approve?beginTime='+beginTime+'&endTime='+endTime+'&alarmTypeCode=1&deviceTypeId=001&fixedPlace=' + fixedPlace + '&page=' + page,
            async: false,
            success: function (result) {
                console.log(result.data)
                $('#alarmStatisticsModal .alarmPlaceListBox tbody').html('');
                for (var i = 0; i < result.data.length; i++) {
                    var beginTime = result.data[i].beginTime;
                    beginTime = moment(beginTime).format("YYYY-MM-DD hh:mm:ss");
                    $('#alarmStatisticsModal .alarmPlaceListBox tbody').append('<tr><td>' + (i + 1) + '</td><td>' + result.data[i].device.deviceName + '</td><td>' + result.data[i].address + '</td><td>' + beginTime + '</td><td>' + result.data[i].device.linkMain1 + '/' + result.data[i].device.linkPhone1 + '</td></tr>');

                }
            }
        });
    }

    //翻页渲染列表
    function randerStatisticsPage(pageSum,beginTime,endTime) {
        console.log(pageSum)
        if (pageSum <= 1) {
            $('#alarmStatisticsModal .pageJump').hide()
        } else {
            $('#alarmStatisticsModal .pageJump').show()
        }
        Page({
            num: pageSum,					//页码数
            startnum: 1,				//指定页码
            elem: $('#alarmStatisticsPage'),		//指定的元素
            callback: function (n) {	//回调函数
                console.log(n);

                $.ajax({
                    url:'/paging/dayAlarm/approve?beginTime='+beginTime+'&endTime='+endTime+'&alarmTypeCode=001&deviceTypeId=001&page='+n,
                    async: false,
                    success: function (result) {
                        console.log(result.data)
                        $('#alarmStatisticsModal .alarmPlaceListBox tbody').html('');
                        for (var i = 0; i < result.data.length; i++) {
                            var beginTime = result.data[i].beginTime;
                            beginTime = moment(beginTime).format("YYYY-MM-DD hh:mm:ss");
                            $('#alarmStatisticsModal .alarmPlaceListBox tbody').append('<tr><td>' +  ((+n - 1) * (+8) + (+i) + (+1)) + '</td><td>' + result.data[i].device.deviceName + '</td><td>' + result.data[i].address + '</td><td>' + beginTime + '</td><td>' + result.data[i].device.linkMain1 + '/' + result.data[i].device.linkPhone1 + '</td></tr>');

                        }
                    }
                });
            }
        });
    }

    //获取总页数
    function statisticsPage(beginTime,endTime) {
        var pageSum;
        $.ajax({
            url:'/paging/dayAlarm/pageNumber?beginTime='+beginTime+'&endTime='+endTime+'&alarmTypeCode=001&deviceTypeId=001',
            //url: '/paging/alarmReasons/pageNumber?beginTime='+beginTime+'&endTime='+endTime+'&alarmCode=001&alarmReasons=' + alarmReasons,
            async: false,
            success: function (result) {
                pageSum = result.data;
                console.log(pageSum,'----------------------')
                randerStatisticsPage(pageSum,beginTime,endTime)
            }
        });
    }
















    //	七日报警
    function sevenAlarmSumDataRander(){
        var alarmDateArrX=[];
        var alarmDateArrY=[];
        var beginTime = moment().add('days', -6).format('YYYY-MM-DD') + " 00:00:00";
        var endTime = moment().add('days', 0).format('YYYY-MM-DD') + " 23:59:59";
        var sevenAlarmCanvas = echarts.init(document.getElementById("sevenAlarmCanvas"));
        var sevenAlarmCanvasoption;
        var start = moment().add('days', -6).format('YYYY-MM-DD');
        var end = moment().add('days', 0).format('YYYY-MM-DD');
        sevenAlarmSumData(alarmDateArrX,alarmDateArrY,start,end,beginTime, endTime,sevenAlarmCanvas,sevenAlarmCanvasoption);
    }

    function sevenAlarmSumData(alarmDateArrX,alarmDateArrY,start,end,beginTime, endTime,sevenAlarmCanvas,sevenAlarmCanvasoption) {
        $.ajax({
            type: "GET",
            url: "/alarm/data/org/device/count?beginTime=" + beginTime + "&endTime=" + endTime + "&alarmTypeCode=001&deviceTypeId=001",
            async: false, //同步执行
            dataType: "json", //返回数据形式为json
            success: function (result) {
                console.log(result)
                if (result) {
                    for (var i = 0; i < result.data.length; i++) {
                        alarmDateArrX.push(result.data[i][0])
                        alarmDateArrY.push(result.data[i][1])
                    }
                }
            },
            error: function (errorMsg) {
                console.log("图表请求失败!");
                myChart.hideLoading();
            }
        });

        var r1 = moment.range(start, end);
        var dataval= Array.from(r1.by('days')).map(m => m.format('YYYY-MM-DD')); // ['01', '02', '03', '04']

        for(var i=0;i< dataval.length;i++){
            if(dataval[i]!=alarmDateArrX[i]){
                //alarmDateArrX[i] = dataval[i];

                alarmDateArrX.splice(i, 0, dataval[i]);
                alarmDateArrY.splice(i, 0, '0');
                //alarmDateArrY[i]='0';
            }
        }
        for(var i=0;i< dataval.length;i++){
            alarmDateArrX[i] = alarmDateArrX[i].substr(8,2)+'日';
        }
        sevenAlarmCanvasFunc(alarmDateArrX, alarmDateArrY, sevenAlarmCanvas,sevenAlarmCanvasoption);
        //return alarmDateArr;
    }

    //七日报警封装
    function sevenAlarmCanvasFunc(alarmDateArrX, alarmDateArrY, sevenAlarmCanvas,sevenAlarmCanvasoption) {
        console.log(alarmDateArrX, alarmDateArrY, sevenAlarmCanvas,sevenAlarmCanvasoption)
        sevenAlarmCanvasoption = {
            color: ['#3398DB'],
            title: {
                //text: '七日内的报警统计',
                textStyle: {
                    fontWeight: 'normal',
                    color: '#fff'
                },
            },
            tooltip: {},
            legend: {
                data: ['报警数量'],
                x: "right",
                padding: 10,
                textStyle: {
                    fontWeight: 'normal',
                    color: '#fff'
                },
                selectedMode: false,//禁止点击
            },
            xAxis: {
                //data: ['01','02','03','04','05','06','07'],
                //data: sevenDayX,
                data:alarmDateArrX,
                boundaryGap: false,
                textStyle: {
                    fontWeight: 'normal',
                    color: '#fff'
                },
                axisLine: {
                    lineStyle: {
                        color: '#fff',
                        width: 1
                    },
                },
            },
            yAxis: [
                {
                    type: 'value',
                    axisLine: {
                        lineStyle: {
                            color: '#fff'
                        }
                    },
                    textStyle: {
                        fontWeight: 'normal',
                        color: '#fff'
                    },
                    axisLabel: {
                        formatter: '{value} 次'
                    }
                }
            ],
            series: [

                {
                    name: '报警数量',
                    type: 'line',
//		                   stack: '总量',
                    symbolSize: 4,
                    smooth: false,   //关键点，为true是不支持虚线的，实线就用true
                    symbolSize: 8,//拐点大小
                    symbol: 'circle',//拐点样式
                    color: '#e55454',
                    barWidth: 28,
                    itemStyle: {
                        normal: {
                            lineStyle: {
                                color: '#e55454',
                                width: 2,
                                type: 'solid'  //'dotted'虚线 'solid'实线
                            }
                        }
                    },
                    //data: alarmDateArr,
                    data:alarmDateArrY,
                },
            ],

            grid: {

                left: '10',
                right: '15',
                bottom: '10',
                top: '40',
                containLabel: true
            },
        };
        sevenAlarmCanvas.setOption(sevenAlarmCanvasoption);
    }

    //响应速度
    function speedFunc() {
        var beginTime = moment().add('days', -6).format('YYYY-MM-DD') + " 00:00:00";
        var endTime = moment().add('days', 0).format('YYYY-MM-DD') + " 23:59:59";
        var dataX = [0.5, 1.0, 1.5, 2.0, 2.5];
        var dataY = [];
        $.ajax({
            url: "http://localhost:9090/response/Speed?beginTime=" + beginTime + "&endTime=" + endTime + "&alarmCode=001",
            async: false,
            success: function (result) {
                dataY[0] = result.data["0.5"];
                dataY[1] = result.data["1.0"];
                dataY[2] = result.data["1.5"];
                dataY[3] = result.data["2.0"];
                dataY[4] = result.data["2.5"];

            }
        })
        var speedCanvas = echarts.init(document.getElementById("speedCanvas"));
        var speedoption = {
            color: ['#3398DB'],
            //tooltip: {
            //	trigger: 'axis',
            //	axisPointer: {            // 坐标轴指示器，坐标轴触发有效
            //		type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            //	}
            //},
            grid: {
                left: '10',
                right: '15',
                bottom: '10',
                top: '40',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'category',
                    data: dataX,
                    axisTick: {
                        alignWithLabel: true
                    },
                    textStyle: {
                        fontWeight: 'normal',
                        color: '#fff'
                    },
                    axisLine: {
                        lineStyle: {
                            color: '#fff',
                            width: 1
                        },
                    },
                }
            ],
            yAxis: [
                {
                    type: 'value',
                    axisLine: {
                        lineStyle: {
                            color: '#fff'
                        }
                    },
                    textStyle: {
                        fontWeight: 'normal',
                        color: '#fff'
                    },
                    axisLabel: {
                        formatter: '{value} 个'
                    }
                }
            ],
            series: [
                {
                    name: '响应速度',
                    type: 'bar',
                    barWidth: '40%',
                    color: '#fdff4a',
                    label: {
                        normal: {
                            show: true,
                            position: 'top',
                            color: '#fff'
                        }
                    },
                    data: dataY
                }
            ]
        };
        speedCanvas.setOption(speedoption);
    }

    //点击三色预警切换

    $(".data .item1").on('click', function () {
        var beginTime = moment().add('days', -60).format('YYYY-MM-DD') + " 00:00:00";
        var endTime = moment().add('days', 0).format('YYYY-MM-DD') + " 23:59:59";
        $(".data .list0").hide();
        $(".data .list2").hide();
        $(".data .list1").show();
        $(".data .listBox").css('background', 'url(/public/images/highDanger.png) no-repeat');
        $.ajax({
            url: '/species/device/count?beginTime=' + beginTime + '&endTime=' + endTime + '&alarmTypeCode=1&fireCount=5',
            success: function (result) {
                $(".data .earlyAlarm .list1 .table").html('')
                for (var i = 0; i < result.data.length; i++) {
                    $(".data .earlyAlarm .list1 .table").append('<p>' + (i + 1) + '.' + result.data[i][0].address + '</p>');
                }

            }
        });
        /* $(this).siblings().hide();
         $(this).parent().find(".earlyWarningColor").show(); */
    });
    $(".data .item2").on('click', function () {
        var beginTime = moment().add('days', -60).format('YYYY-MM-DD') + " 00:00:00";
        var endTime = moment().add('days', 0).format('YYYY-MM-DD') + " 23:59:59";
        $(".data .list0").hide();
        $(".data .list1").hide();
        $(".data .list2").show();
        $(".data .listBox").css('background', 'url(/public/images/normalDanger.png) no-repeat');
        $.ajax({
            url: '/species/device/count?beginTime=' + beginTime + '&endTime=' + endTime + '&alarmTypeCode=1&fireCount=10',
            success: function (result) {
                $(".data .earlyAlarm .list2 .table").html('')
                for (var i = 0; i < result.data.length; i++) {
                    $(".data .earlyAlarm .list2 .table").append('<p>' + (i + 1) + '.' + result.data[i][0].address + '</p>');
                }

            }
        });
        /* $(this).siblings().hide();
         $(this).parent().find(".earlyWarningColor").show(); */
    });

    //三色预警
    function earlylist0() {
        var beginTime = moment().add('days', -60).format('YYYY-MM-DD') + " 00:00:00";
        var endTime = moment().add('days', 0).format('YYYY-MM-DD') + " 23:59:59";
        $(".data .list0").show();
        $(".data .list1").hide();
        $(".data .list2").hide();
        $(".data .listBox").css('background', 'url(/public/images/middleDanger.png) no-repeat');
        $.ajax({
            url: '/species/device/count?beginTime=' + beginTime + '&endTime=' + endTime + '&alarmTypeCode=1&fireCount=2',
            success: function (result) {
                $(".data .earlyAlarm .list0 .table").html('')
                for (var i = 0; i < result.data.length; i++) {
                    $(".data .earlyAlarm .list0 .table").append('<p>' + (i + 1) + '.' + result.data[i][0].address + '</p>')
                }

            }
        });
    }

    $(".data .item0").on('click', function () {
        earlylist0();
        /* $(this).siblings().hide();
         $(this).parent().find(".earlyWarningColor").show(); */
    });


    //		重点关注
    function sevenFocusCanvasTime() {
        var statisticsFocusNum = [];
        var statisticsFocusAdd = [];
        var statisticsFocusAdd1 = [];
        var beginTime = moment().add('days', -6).format('YYYY-MM-DD') + " 00:00:00";
        var endTime = moment().add('days', 0).format('YYYY-MM-DD') + " 23:59:59";
        var data = [];
        $.ajax({
            url: "/alarm/data/device/count?beginTime=" + beginTime + "&endTime=" + endTime + "&alarmTypeCode=1&deviceTypeId=001",
            type: 'GET',
            async: false, //同步执行
            success: function (result) {
                console.log(result)
                if (result.status == 200) {
                    for (var i = 0; i < result.data.length; i++) {
                        data = result.data;

                    }
                } else {
                    //winTip.alert(result.message);
                }
            }
        });
        var dataValue = [];
        for (var i = 0; i < data.length; i++) {
            dataValue.push(data[i][1])
        }
        console.log(dataValue)
        var maxInNumbers = Math.max.apply(Math, dataValue);
        maxInNumbers = maxInNumbers * 2;
        console.log(maxInNumbers)
        var sevenFocusCanvas = echarts.init(document.getElementById("sevenFocusCanvas"));
        var title = '重点对象';

        var option = {
            //  backgroundColor: '#25499F',
            baseOption: {
                animationDurationUpdate: 1000,
                animationEasingUpdate: 'quinticInOut',
                timeline: {
                    axisType: 'category',
                    orient: 'vertical',
                    autoPlay: true,
                    //  inverse: true,
                    playInterval: 5000,
                    left: null,
                    right: 30,
                    top: 330,
                    bottom: 100,
                    width: 40,
                    height: null,
                    label: {
                        normal: {
                            show: true,
                            interval: 0,
                            //  textStyle: {
                            //  color: '#ddd'
                            //  }
                        },
                        //  emphasis: {
                        //      textStyle: {
                        //          color: '#fff'
                        //      }
                        //  }
                    },
                    symbol: 'none',
                    lineStyle: {
                        color: '#ccc',
                        show: false
                    },
                    checkpointStyle: {
                        symbol: 'none',
                        color: '#bbb',
                        borderColor: '#777',
                        show: false,
                        borderWidth: 1
                    },
                    controlStyle: {
                        showNextBtn: false,
                        showPrevBtn: false,
                        normal: {
                            color: '#666',
                            show: false,
                            borderColor: '#666'
                        },
                        emphasis: {
                            color: '#aaa',
                            borderColor: '#aaa'
                        }
                    },
                    //data: data.map(function(ele) {
                    //	return ele.time
                    //})
                    //data:title
                },
                //  backgroundColor: '#25499F',
                title: [{
                    left: 'left',
                    top: '10%',
                    textStyle: {
                        fontSize: 16,
                        fontWeight: "normal",
                        color: '#fff'
                    }
                },
                    //	{
                    //	left: 'center',
                    //	top: '5%'
                    //}
                ],
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis: {},
                yAxis: {},
                series: [

                    {
                        id: 'bar',
                        type: 'bar',
//						tooltip: {
//							show: false
//						},
                        tooltip: {
                            trigger: 'item',
                            formatter: "{a} <br/>{b} : {c} ({d}%)"
                        },
                        label: {
                            normal: {
                                show: true,
                                position: 'right',
                                textStyle: {
                                    color: '#fff'
                                }
                            }
                        },
                        barWidth: '30%',//柱图宽度
                        data: []
                    },

                ]
            },
            options: []
        }


        option.options.push({
            title: {
                //text: data[0].time
                text: title
            },

            xAxis: [
                {
                    type: 'value',
                    axisTick: {
                        alignWithLabel: true
                    },
                    axisLine: {
                        lineStyle: {
                            type: 'solid',
                            color: '#fff',//左边线的颜色
                            width: '1'//坐标线的宽度
                        }
                    },
                    max: maxInNumbers,
                }
            ],
            yAxis: {
                type: 'category',
                axisLabel: {
                    show: false,
                    textStyle: {
                        color: '#fff'
                    }
                },
                axisLine: {
                    lineStyle: {
                        type: 'solid',
                        color: '#fff',//左边线的颜色
                        width: '1'//坐标线的宽度
                    }
                },
                //do------------------------------------------------------------
                data: data.map(function (ele) {
                    return ele[0].address
                }).reverse(),
            },
            series: [

                {
                    id: 'bar',
                    label: {
                        normal: {
                            position: 'right',
                            formatter: '{b} : {c}'
                        }
                    },
                    data: data.map(function (ele) {
                        console.log(ele[1])
                        return ele[1]
                    }).sort(function (a, b) {
                        return a > b
                    })
                },

            ]
        })


        sevenFocusCanvas.setOption(option);
    }


//	报警来源柱状图
    function alarmSourceCharts1Func() {
        var weekOfday = moment().format('E');//这周的第几天
        //周一
        var beginTime = moment().add('days', 1).subtract(weekOfday, 'days').format('YYYY-MM-DD') + ' 00:00:00';
        //周日
        var endTime = moment().add('days', 7).subtract(weekOfday, 'days').format('YYYY-MM-DD') + ' 23:59:59';
        var alarmSource = [];
        var alarmSourceName = [];
        $.ajax({
            //url:'/alarm/data/org/device/Typecount?beginTime='+beginTime+'&endTime='+endTime+'&alarmTypeCode=1&deviceTypeId=001',
            url: '/alarm/data/org/device/fixcount?beginTime=' + beginTime + '&endTime=' + endTime + '&alarmTypeCode=1&deviceTypeId=001',
            async: false,
            success: function (result) {
                console.log(result.data)
                alarmSource = result.data;
                for (var i = 0; i < result.data.length; i++) {
                    alarmSourceName.push(result.data[i].name);

                    //if(result.data[i]==)
                }
            }
        });
        alarmSourceCharts1(beginTime, endTime, alarmSource, alarmSourceName);
        sourceYearOnYear(beginTime, endTime);
    }

    //封装报警来源同比及数量
    function sourceYearOnYear(beginTime, endTime) {
        $.ajax({
            url: '/alarm//data/fixedPlace/yoy?beginTime=' + beginTime + '&endTime=' + endTime + '&alarmTypeCode=1&deviceTypeId=001&fixedPlace=出租房',
            async: false,
            success: function (result) {
                console.log(result.data)
                $('#alarmSourceModal-ChartsList ul li').eq(1).find('span').eq(1).text(result.data.currAlarmcount);
                $('#alarmSourceModal-ChartsList ul li').eq(1).find('span').eq(2).find('i').text(result.data.value + '%');

            }
        });
        $.ajax({
            url: '/alarm//data/fixedPlace/yoy?beginTime=' + beginTime + '&endTime=' + endTime + '&alarmTypeCode=1&deviceTypeId=001&fixedPlace=居民房',
            async: false,
            success: function (result) {
                console.log(result.data)
                $('#alarmSourceModal-ChartsList ul li').eq(2).find('span').eq(1).text(result.data.currAlarmcount);
                $('#alarmSourceModal-ChartsList ul li').eq(2).find('span').eq(2).find('i').text(result.data.value + '%');

            }
        });
        $.ajax({
            url: '/alarm//data/fixedPlace/yoy?beginTime=' + beginTime + '&endTime=' + endTime + '&alarmTypeCode=1&deviceTypeId=001&fixedPlace=公共区域',
            async: false,
            success: function (result) {
                console.log(result.data)
                $('#alarmSourceModal-ChartsList ul li').eq(3).find('span').eq(1).text(result.data.currAlarmcount);
                $('#alarmSourceModal-ChartsList ul li').eq(3).find('span').eq(2).find('i').text(result.data.value + '%');

            }
        });
        $.ajax({
            url: '/alarm//data/fixedPlace/yoy?beginTime=' + beginTime + '&endTime=' + endTime + '&alarmTypeCode=1&deviceTypeId=001&fixedPlace=经营场所',
            async: false,
            success: function (result) {
                console.log(result.data)
                $('#alarmSourceModal-ChartsList ul li').eq(4).find('span').eq(1).text(result.data.currAlarmcount);
                $('#alarmSourceModal-ChartsList ul li').eq(4).find('span').eq(2).find('i').text(result.data.value + '%');

            }
        });
    }

    //报警来源图表
    function alarmSourceCharts() {
        var weekOfday = moment().format('E');//这周的第几天
        //周一
        var beginTime = moment().add('days', 1).subtract(weekOfday, 'days').format('YYYY-MM-DD') + ' 00:00:00';
        //周日
        var endTime = moment().add('days', 7).subtract(weekOfday, 'days').format('YYYY-MM-DD') + ' 23:59:59';

        var alarmSource = [];
        var alarmSourceName = [];
        $.ajax({
            //url:'/alarm/data/org/device/Typecount?beginTime='+beginTime+'&endTime='+endTime+'&alarmTypeCode=1&deviceTypeId=001',
            url: '/alarm/data/org/device/fixcount?beginTime=' + beginTime + '&endTime=' + endTime + '&alarmTypeCode=1&deviceTypeId=001',
            async: false,
            success: function (result) {
                console.log(result.data)
                alarmSource = result.data;
                for (var i = 0; i < result.data.length; i++) {
                    alarmSourceName.push(result.data[i].name)
                }
            }
        });

        //var alarmSource=[
        //	{value:10, name:'rose1'},
        //	{value:16, name:'rose4'},
        //	{value:12, name:'rose2'},
        //	{value:18, name:'rose5'},
        //	{value:14, name:'rose3'},
        //	{value:20, name:'rose6'}
        //]
        var alarmSourceCanva = echarts.init(document.getElementById('alarmSourceCanva'));
        var alarmSourceoption = {
            title: {
                text: '报警来源',
                // subtext: '纯属虚构',
                textStyle: {
                    fontWeight: 'normal',
                    color: '#fff'
                },
                x: '1%',
                y: '1%'
            },
            tooltip: {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            legend: {
                orient: 'vertical',
                bottom: '5%',
                left: '1%',
//				data:['rose1','rose2','rose3','rose4','rose5','rose6'],
                data: alarmSourceName,
                selectedMode: false,//禁止点击
                textStyle: {
                    fontWeight: 'normal',
                    color: '#fff'
                },
            },
            calculable: true,
            series: [
                {
                    name: '报警来源',
                    type: 'pie',
                    radius: [20, 80],
                    center: ['50%', '50%'],
                    roseType: 'radius',
                    data: alarmSource,
                    label: {            //饼图图形上的文本标签
                        normal: {
                            show: true,
                            position: 'inner', //标签的位置
                            textStyle: {
                                fontWeight: 300,
                                color: '#fff',
                                fontSize: 12    //文字的字体大小
                            },
                            formatter: '{d}%'
                        }
                    },
                },
                {
                    name: '报警来源',
                    type: 'pie',
                    radius: [20, 80],
                    // radius : [109, 110],
                    center: ['50%', '50%'],
                    roseType: 'radius',
                    data: alarmSource,
                    label: {            //饼图图形上的文本标签
                        normal: {
                            show: true,
                            // position:'inner', //标签的位置
                            textStyle: {
                                fontWeight: 300,
                                color: '#fff',
                                fontSize: 12    //文字的字体大小
                            },
                            // formatter:'{d}%'
                        }
                    },
                }
            ]
        };
        alarmSourceCanva.setOption(alarmSourceoption);
    }

    //报警总数数量和同比
    function alarmFunc() {
        $.ajax({
            url: '/yoy/alarmValue',
            success: function (result) {
                console.log(result.data)
                for (var i = 0; i < result.data.length; i++) {
                    alarmCount.push(result.data[i][0].secondCount);
                    alarmPercent.push(result.data[i][0].value);
                }
                alarmCount[0] = alarmCount[0]?alarmCount[0]:'0';
                alarmPercent[0] = alarmPercent[0]?alarmPercent[0]:'0';
                alarmSourceSumRunderFunc(alarmCount[0], alarmPercent[0]);
                alarmCauseSumRunderFunc(alarmCount[0], alarmPercent[0]);
            }
        });
    }

    //封装添加报警总数和同比
    function alarmSourceSumRunderFunc(num, value) {
        $('#alarmSourceModal-ChartsList ul li').eq(0).find('span').eq(1).text(num);
        $('#alarmSourceModal-ChartsList ul li').eq(0).find('span').eq(2).find('i').text(value + '%');
    }

    function alarmCauseSumRunderFunc(num, value) {
        $('#alarmCauseModal-ChartsList ul li').eq(0).find('span').eq(1).text(num);
        $('#alarmCauseModal-ChartsList ul li').eq(0).find('span').eq(2).find('i').text(value + '%');

    }

    //点击报警来源时间筛选框，按时间筛选
    $('.data #alarmSourceModal-dataBox ul li').on('click', function () {
        var text = $(this).text();
        $('.data #alarmSourceModal-week').text(text);
        var mydata = $(this).attr('mydata');
        var weekOfday = moment().format('E');//这周的第几天
        var startTime, endTime;
        if (mydata == "week") {
            //周一
            startTime = moment().add('days', 1).subtract(weekOfday, 'days').format('YYYY-MM-DD');
            //周日
            endTime = moment().add('days', 7).subtract(weekOfday, 'days').format('YYYY-MM-DD');
            alarmSourceSumRunderFunc(alarmCount[0], alarmPercent[0])
        } else if (mydata == "month") {
            //月初
            startTime = moment().startOf('month').format("YYYY-MM-DD");
            //月末
            endTime = moment().endOf('month').format("YYYY-MM-DD");
            alarmSourceSumRunderFunc(alarmCount[1], alarmPercent[1])
        } else if (mydata == "quarter") {
            var monthDaysArr = nowQuarter();
            startTime = monthDaysArr[0];
            endTime = monthDaysArr[1];
            alarmSourceSumRunderFunc(alarmCount[2], alarmPercent[2])
        }
        startTime += ' 00:00:00';
        endTime += ' 23:59:59';
        sourceBeginTime = startTime;
        sourceEndTime = endTime;
        console.log(sourceBeginTime,sourceEndTime)
        var alarmSource = [];
        var alarmSourceName = [];
        $.ajax({
            url: '/alarm/data/org/device/fixcount?beginTime=' + startTime + '&endTime=' + endTime + '&alarmTypeCode=1&deviceTypeId=001',
            async: false,
            success: function (result) {
                console.log(result.data)
                alarmSource = result.data;
                for (var i = 0; i < result.data.length; i++) {
                    alarmSourceName.push(result.data[i].name)
                }
            }
        });
        alarmSourceCharts1(startTime, endTime, alarmSource, alarmSourceName);
        sourceYearOnYear(startTime, endTime);
        sourcePage(fixedPlace,sourceBeginTime,sourceEndTime);
        sourceRanderListPage(fixedPlace, 1,sourceBeginTime,sourceEndTime);
    });
    //获取本季度
    function nowQuarter() {
        var currentQuarter = moment().quarter(); // 当前是第几季度
        var currentYear = moment().year();

        var endMonth = 3 * parseInt(currentQuarter) //当季度最后一个月
        var startMonth = 3 * parseInt(currentQuarter) - 2;
        /* 对月数进行格式化 */
        if (startMonth < 10) {
            startMonth = '0' + startMonth
        } else {
            startMonth += ''
        }

        if (endMonth < 10) {
            endMonth = '0' + endMonth
        } else {
            endMonth += ''
        }
        var startMonthDays = currentYear + '-' + startMonth + '-01'; // 末尾月天数
        var endMonthDays = moment(currentYear + '-' + endMonth).daysInMonth(); // 末尾月天数
        var endMonthDays = currentYear + '-' + endMonth + '-' + endMonthDays //完整年月日整合
        var monthDaysArr = [];
        monthDaysArr.push(startMonthDays)
        monthDaysArr.push(endMonthDays)
        console.log(monthDaysArr,'----------------------------')
        return monthDaysArr;
    }

    //报警来源分页
    $("#alarmSourceBtnBox ul li").on('click', function () {
        var index = $(this).index();
        console.log(index)
        if (index == 0) {
            fixedPlace = 'all';
        } else if (index == 1) {
            fixedPlace = '出租房';
        } else if (index == 2) {
            fixedPlace = '居民房';
        } else if (index == 3) {
            fixedPlace = '公共区域';
        } else if (index == 4) {
            fixedPlace = '经营场所';
        }
        console.log(sourceBeginTime,sourceEndTime);
        sourcePage(fixedPlace,sourceBeginTime,sourceEndTime);
        sourceRanderListPage(fixedPlace, 1,sourceBeginTime,sourceEndTime);
    });
    //渲染列表数据
    function sourceRanderListPage(fixedPlace, page,beginTime,endTime) {
        $.ajax({
            url: '/paging/fixedPlace/approve?beginTime='+beginTime+'&endTime='+endTime+'&alarmTypeCode=1&deviceTypeId=001&fixedPlace=' + fixedPlace + '&page=' + page,
            async: false,
            success: function (result) {
                console.log(result.data)
                $('#alarmSourceModal .alarmPlaceListBox tbody').html('');
                for (var i = 0; i < result.data.length; i++) {
                    var beginTime = result.data[i].beginTime;
                    beginTime = moment(beginTime).format("YYYY-MM-DD hh:mm:ss");
                    var fixedPlace = result.data[i].device.fixedPlace?result.data[i].device.fixedPlace:'';
                    $('#alarmSourceModal .alarmPlaceListBox tbody').append('<tr><td>' + (i + 1) + '</td><td>' + result.data[i].device.deviceName + '</td><td>' + result.data[i].address + '</td><td>' + fixedPlace + '</td><td>' + beginTime + '</td><td>' + result.data[i].device.linkMain1 + '/' + result.data[i].device.linkPhone1 + '</td></tr>');

                }
            }
        });
    }

    //翻页渲染列表
    function randerSourcePage(pageSum, fixedPlace,beginTime,endTime) {
        console.log(pageSum)
        if (pageSum <= 1) {
            $('#alarmSourceModal .pageJump').hide()
        } else {
            $('#alarmSourceModal .pageJump').show()
        }
        Page({
            num: pageSum,					//页码数
            startnum: 1,				//指定页码
            elem: $('#alarmPlacePage'),		//指定的元素
            callback: function (n) {	//回调函数
                console.log(n);

                $.ajax({
                    url: '/paging/fixedPlace/approve?beginTime='+beginTime+'&endTime='+endTime+'&alarmTypeCode=1&deviceTypeId=001&fixedPlace=' + fixedPlace + '&page=' + n,
                    async: false,
                    success: function (result) {
                        console.log(result.data)
                        $('#alarmSourceModal .alarmPlaceListBox tbody').html('');
                        for (var i = 0; i < result.data.length; i++) {
                            var beginTime = result.data[i].beginTime;
                            beginTime = moment(beginTime).format("YYYY-MM-DD hh:mm:ss");
                            var fixedPlace = result.data[i].device.fixedPlace?result.data[i].device.fixedPlace:'';
                            $('#alarmSourceModal .alarmPlaceListBox tbody').append('<tr><td>' +  ((+n - 1) * (+8) + (+i) + (+1)) + '</td><td>' + result.data[i].device.deviceName + '</td><td>' + result.data[i].address + '</td><td>' + fixedPlace + '</td><td>' + beginTime + '</td><td>' + result.data[i].device.linkMain1 + '/' + result.data[i].device.linkPhone1 + '</td></tr>');

                        }
                    }
                });
            }
        });
    }

    //获取总页数
    function sourcePage(fixedPlace,startTIme,endTime) {
        var pageSum;
        $.ajax({
            url: '/paging/fixedPlace/pageNumber?beginTime='+startTIme+'&endTime='+endTime+'&alarmTypeCode=1&deviceTypeId=001&fixedPlace=' + fixedPlace,
            async: false,
            success: function (result) {
                pageSum = result.data;
                console.log(pageSum,'---------------------')

                randerSourcePage(pageSum, fixedPlace,startTIme,endTime)
            }
        });
    }

    //模态框中的图表
    function alarmSourceCharts1(beginTime, endTime, alarmSource, alarmSourceName) {

        var alarmSourceCanva1 = echarts.init(document.getElementById('alarmSourceCanva1'));
        var alarmSourceoption = {
            title: {
                //text: '报警来源',
                textStyle: {
                    fontWeight: 'normal',
                    color: '#fff'
                },
                x: '1%',
                y: '1%'
            },
            tooltip: {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
//			legend: {
//				orient: 'vertical',
//				bottom : '5%',
//				left : '1%',
//				data:alarmSourceName,
//				selectedMode: false,//禁止点击
//				textStyle: {
//					fontWeight: 'normal',
//					color: '#fff'
//				},
//			},
            calculable: true,
            series: [
                {
                    name: '报警来源',
                    type: 'pie',
                    radius: [20, 80],
                    center: ['60%', '50%'],
                    roseType: 'radius',
                    data: alarmSource,
                    label: {            //饼图图形上的文本标签
                        normal: {
                            show: true,
                            position: 'inner', //标签的位置
                            textStyle: {
                                fontWeight: 300,
                                color: '#fff',
                                fontSize: 12    //文字的字体大小
                            },
                            formatter: '{d}%'
                        }
                    },
                },
                {
                    name: '报警来源',
                    type: 'pie',
                    radius: [20, 80],
                    // radius : [109, 110],
                    center: ['60%', '50%'],
                    roseType: 'radius',
                    data: alarmSource,
                    label: {            //饼图图形上的文本标签
                        normal: {
                            show: true,
                            // position:'inner', //标签的位置
                            textStyle: {
                                fontWeight: 300,
                                color: '#fff',
                                fontSize: 12    //文字的字体大小
                            },
                            // formatter:'{d}%'
                        }
                    },
                }
            ]
        };
        alarmSourceCanva1.setOption(alarmSourceoption);
    }

    //报警原因
    function alarmCauseCharts() {

        var beginTime = moment().add('days', -6).format('YYYY-MM-DD') + " 00:00:00";
        var endTime = moment().add('days', 0).format('YYYY-MM-DD') + " 23:59:59";
        var alarmCauseData = [];
        var alarmCauseName = [];
        $.ajax({
            url: '/alarm/data/org/device/Typecount?beginTime=' + beginTime + '&endTime=' + endTime + '&alarmTypeCode=1&deviceTypeId=001',
            async: false,
            success: function (result) {
                console.log(result.data)
                alarmCauseData = result.data;
                for (var i = 0; i < result.data.length; i++) {
                    alarmCauseName.push(result.data[i].name);
                }
            }
        });
        var alarmCauseCanvas = echarts.init(document.getElementById('alarmCauseCanvas'));
        alarmCauseoption = {
            title: {
                text: '报警原因',
                textStyle: {
                    fontWeight: 'normal',
                    color: '#fff'
                },
                x: '1%',
                y: '1%'
            },
            tooltip: {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            legend: {
                orient: 'vertical',
                //left: 'left',
                //bottom: 'left',
                left: '1%',
                bottom: '5%',
                selectedMode: false,//禁止点击
                textStyle: {
                    fontWeight: 'normal',
                    color: '#fff'
                },
                data: alarmCauseName
            },
            series: [
                {
                    name: '报警来源',
                    type: 'pie',
                    radius: '55%',
                    center: ['50%', '60%'],
                    data: alarmCauseData,
                    label: {
                        normal: {
                            position: 'right',
                            textStyle: {
                                fontWeight: 300,
                                color: '#fff',
                                fontSize: 12    //文字的字体大小
                            },
                            formatter: '{b} ({d}%)'
                        }
                    },
                    itemStyle: {
                        emphasis: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }
            ]
        };
        alarmCauseCanvas.setOption(alarmCauseoption);
    }

//	报警原因二级模态框
    function alarmCauseCharts1Func() {
        var weekOfday = moment().format('E');//这周的第几天
        //周一
        var beginTime = moment().add('days', 1).subtract(weekOfday, 'days').format('YYYY-MM-DD') + ' 00:00:00';
        //周日
        var endTime = moment().add('days', 7).subtract(weekOfday, 'days').format('YYYY-MM-DD') + ' 23:59:59';
        var alarmCause = [];
        var alarmCauseName = [];
        $.ajax({
            //url:'/alarm/data/org/device/Typecount?beginTime='+beginTime+'&endTime='+endTime+'&alarmTypeCode=1&deviceTypeId=001',
            url: '/alarm/data/org/device/fixcount?beginTime=' + beginTime + '&endTime=' + endTime + '&alarmTypeCode=1&deviceTypeId=001',
            async: false,
            success: function (result) {
                console.log(result.data)
                alarmCause = result.data;
                for (var i = 0; i < result.data.length; i++) {
                    alarmCauseName.push(result.data[i].name)
                }
            }
        });
        alarmCauseCharts1(beginTime, endTime, alarmCause, alarmCauseName);
//--------------------------------------------------------------TODO----------------------------------------------
        causeYearOnYear(beginTime, endTime);

    }

    //获取同比和报警数量
    function causeYearOnYear(beginTime, endTime) {
        $.ajax({
            url: '/alarm/data/alarmReason/yoy?beginTime=' + beginTime + '&endTime=' + endTime + '&alarmTypeCode=1&deviceTypeId=001&alarmReasons=炊烟',
            success: function (result) {
                $('#alarmCauseModal-ChartsList ul li').eq(1).find('span').eq(1).text(result.data.currAlarmcount);
                $('#alarmCauseModal-ChartsList ul li').eq(1).find('span').eq(2).find('i').text(result.data.value + '%');
            }
        });
        $.ajax({
            url: '/alarm/data/alarmReason/yoy?beginTime=' + beginTime + '&endTime=' + endTime + '&alarmTypeCode=1&deviceTypeId=001&alarmReasons=吸烟',
            success: function (result) {
                $('#alarmCauseModal-ChartsList ul li').eq(2).find('span').eq(1).text(result.data.currAlarmcount);
                $('#alarmCauseModal-ChartsList ul li').eq(2).find('span').eq(2).find('i').text(result.data.value + '%');
            }
        });
        $.ajax({
            url: '/alarm/data/alarmReason/yoy?beginTime=' + beginTime + '&endTime=' + endTime + '&alarmTypeCode=1&deviceTypeId=001&alarmReasons=粉尘',
            success: function (result) {
                $('#alarmCauseModal-ChartsList ul li').eq(3).find('span').eq(1).text(result.data.currAlarmcount);
                $('#alarmCauseModal-ChartsList ul li').eq(3).find('span').eq(2).find('i').text(result.data.value + '%');
            }
        });
        $.ajax({
            url: '/alarm/data/alarmReason/yoy?beginTime=' + beginTime + '&endTime=' + endTime + '&alarmTypeCode=1&deviceTypeId=001&alarmReasons=火警',
            success: function (result) {
                $('#alarmCauseModal-ChartsList ul li').eq(4).find('span').eq(1).text(result.data.currAlarmcount);
                $('#alarmCauseModal-ChartsList ul li').eq(4).find('span').eq(2).find('i').text(result.data.value + '%');
            }
        });
        $.ajax({
            url: '/alarm/data/alarmReason/yoy?beginTime=' + beginTime + '&endTime=' + endTime + '&alarmTypeCode=1&deviceTypeId=001&alarmReasons=其他',
            success: function (result) {
                $('#alarmCauseModal-ChartsList ul li').eq(5).find('span').eq(1).text(result.data.currAlarmcount);
                $('#alarmCauseModal-ChartsList ul li').eq(5).find('span').eq(2).find('i').text(result.data.value + '%');
            }
        });
    }


    //点击报警原因时间筛选框，按时间筛选
    $('.data #alarmCauseModal-dataBox ul li').on('click', function () {
        var text = $(this).text();
        $('.data #alarmCauseModal-week').text(text);
        var mydata = $(this).attr('mydata');
        //-------------------------------TODO---------------------------
        var weekOfday = moment().format('E');//这周的第几天
        var startTime, endTime;
        if (mydata == "week") {
            //周一
            startTime = moment().add('days', 1).subtract(weekOfday, 'days').format('YYYY-MM-DD');
            //周日
            endTime = moment().add('days', 7).subtract(weekOfday, 'days').format('YYYY-MM-DD');
            alarmCauseSumRunderFunc(alarmCount[0], alarmPercent[0])
        } else if (mydata == "month") {
            //月初
            startTime = moment().startOf('month').format("YYYY-MM-DD");
            //月末
            endTime = moment().endOf('month').format("YYYY-MM-DD");
            alarmCauseSumRunderFunc(alarmCount[1], alarmPercent[1])
        } else if (mydata == "quarter") {
            var monthDaysArr = nowQuarter();
            startTime = monthDaysArr[0];
            endTime = monthDaysArr[1];
            alarmCauseSumRunderFunc(alarmCount[2], alarmPercent[2])
        }
        startTime += ' 00:00:00';
        endTime += ' 23:59:59';
        causeBeginTime=startTime;
        causeEndTime=endTime;
        var alarmCause = [];
        var alarmCauseName = [];
        $.ajax({
            //url:'/alarm/data/org/device/Typecount?beginTime='+beginTime+'&endTime='+endTime+'&alarmTypeCode=1&deviceTypeId=001',
            url: '/alarm/data/org/device/fixcount?beginTime=' + startTime + '&endTime=' + endTime + '&alarmTypeCode=1&deviceTypeId=001',
            async: false,
            success: function (result) {
                console.log(result.data)
                alarmCause = result.data;
                for (var i = 0; i < result.data.length; i++) {
                    alarmCauseName.push(result.data[i].name)
                }
            }
        });
        alarmCauseCharts1(startTime, endTime, alarmCause, alarmCauseName);
        causeYearOnYear(startTime, endTime);
        causeRanderListPage(alarmReasons, 1,causeBeginTime,causeEndTime);
        causePage(alarmReasons,causeBeginTime,causeEndTime);
    })

    //报警原因分页
    $('.data .alarmPlaceBtnBox ul li').click(function () {
        $(this).addClass('active').siblings().removeClass('active');
    })
    $("#alarmCauseBtnBox ul li").on('click', function () {
        var index = $(this).index();
        console.log(index)
        if (index == 0) {
            alarmReasons = 'all';
        } else if (index == 1) {
            alarmReasons = '炊烟';
        } else if (index == 2) {
            alarmReasons = '吸烟';
        } else if (index == 3) {
            alarmReasons = '粉尘';
        } else if (index == 4) {
            alarmReasons = '火警';
        } else if (index == 5) {
            alarmReasons = '其他';
        }
        causePage(alarmReasons,causeBeginTime,causeEndTime);
        causeRanderListPage(alarmReasons, 1,causeBeginTime,causeEndTime)
    });
    function causeRanderListPage(alarmReasons, page,beginTime,endTime) {
        $.ajax({
            url: '/paging/alarmReasons/approve?beginTime='+beginTime+'&endTime='+endTime+'&alarmCode=001&alarmReasons=' + alarmReasons + '&page=' + page,
            async: false,
            success: function (result) {
                console.log(result.data)
                $('#alarmCauseModal .alarmPlaceListBox tbody').html('');
                for (var i = 0; i < result.data.length; i++) {
                    var alarmReasons = result.data[i].alarmReasons?result.data[i].alarmReasons:'';
                    var beginTime = result.data[i].beginTime;
                    beginTime = moment(beginTime).format("YYYY-MM-DD hh:mm:ss");
                    $('#alarmCauseModal .alarmPlaceListBox tbody').append('<tr><td>' + (i + 1) + '</td><td>' + result.data[i].device.deviceName + '</td><td>' + result.data[i].address + '</td><td>' + alarmReasons + '</td><td>' + beginTime + '</td><td>' + result.data[i].device.linkMain1 + '/' + result.data[i].device.linkPhone1 + '</td></tr>');

                }
            }
        });
    }

    //翻页渲染列表
    function randerCausePage(pageSum, alarmReasons,beginTime,endTime) {

        if (pageSum <= 1) {
            $('#alarmCauseModal .pageJump').hide()
        } else {
            $('#alarmCauseModal .pageJump').show()
        }
        Page({
            num: pageSum,					//页码数
            startnum: 1,				//指定页码
            elem: $('#alarmCausePage'),		//指定的元素
            callback: function (n) {	//回调函数
                $.ajax({
                    url: '/paging/alarmReasons/approve?beginTime='+beginTime+'&endTime='+endTime+'&alarmCode=001&alarmReasons=' + alarmReasons + '&page=' + n,
                    async: false,
                    success: function (result) {
                        console.log(result.data)
                        $('#alarmCauseModal .alarmPlaceListBox tbody').html('');
                        for (var i = 0; i < result.data.length; i++) {
                            var alarmReasons = result.data[i].alarmReasons?result.data[i].alarmReasons:'';
                            var beginTime = result.data[i].beginTime;
                            beginTime = moment(beginTime).format("YYYY-MM-DD hh:mm:ss");
                            $('#alarmCauseModal .alarmPlaceListBox tbody').append('<tr><td>' +  ((+n - 1) * (+8) + (+i) + (+1)) + '</td><td>' + result.data[i].device.deviceName + '</td><td>' + result.data[i].address + '</td><td>' + alarmReasons + '</td><td>' + beginTime + '</td><td>' + result.data[i].device.linkMain1 + '/' + result.data[i].device.linkPhone1 + '</td></tr>');

                        }
                    }
                });
            }
        });
    }

    //获取总页数
    function causePage(alarmReasons,beginTime,endTime) {
        var pageSum;
        $.ajax({
            url: '/paging/alarmReasons/pageNumber?beginTime='+beginTime+'&endTime='+endTime+'&alarmCode=001&alarmReasons=' + alarmReasons,
            async: false,
            success: function (result) {
                pageSum = result.data;
                console.log(pageSum,'----------------------')
                randerCausePage(pageSum, alarmReasons,beginTime,endTime)
            }
        });
    }

    //报警原因模态框中的图表
    function alarmCauseCharts1(beginTime, endTime, alarmCause, alarmCauseName) {

        var alarmCauseCanva1 = echarts.init(document.getElementById('alarmCauseCanva1'));
        var alarmCauseoption = {
            title: {
                //text: '报警来源',
                textStyle: {
                    fontWeight: 'normal',
                    color: '#fff'
                },
                x: '1%',
                y: '1%'
            },
            tooltip: {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
//			legend: {
//				orient: 'vertical',
//				bottom : '5%',
//				left : '1%',
//				data:alarmCauseName,
//				selectedMode: false,//禁止点击
//				textStyle: {
//					fontWeight: 'normal',
//					color: '#fff'
//				},
//			},
            calculable: true,
            series: [
                {
                    name: '报警来源',
                    type: 'pie',
                    radius: [20, 80],
                    center: ['60%', '50%'],
                    roseType: 'radius',
                    data: alarmCause,
                    label: {            //饼图图形上的文本标签
                        normal: {
                            show: true,
                            position: 'inner', //标签的位置
                            textStyle: {
                                fontWeight: 300,
                                color: '#fff',
                                fontSize: 12    //文字的字体大小
                            },
                            formatter: '{d}%'
                        }
                    },
                },
                {
                    name: '报警来源',
                    type: 'pie',
                    radius: [20, 80],
                    // radius : [109, 110],
                    center: ['60%', '50%'],
                    roseType: 'radius',
                    data: alarmCause,
                    label: {            //饼图图形上的文本标签
                        normal: {
                            show: true,
                            // position:'inner', //标签的位置
                            textStyle: {
                                fontWeight: 300,
                                color: '#fff',
                                fontSize: 12    //文字的字体大小
                            },
                            // formatter:'{d}%'
                        }
                    },
                }
            ]
        };
        alarmCauseCanva1.setOption(alarmCauseoption);
    }

    //------------------------------------------------------------------------------
    //数据统计弹出层

    //关闭设备总数模态框
    $(".data .deviceModal-close").on('click', function () {
        $(".data .alarmModalBox").modal('hide');
        $(".data #deviceModalBox").modal('hide');
        $(".data #alarmSumModalBox").modal('hide');
        $(".data #untreatedDataModalBox").modal('hide');
    });
    //开启设备总数模态框
    $(".data .sevenDataAlarm .sevenDataNumCenter").on('click', function () {
        $(".data #alarmSumModalBox").modal('show');
        //sourceRanderListPage(fixedPlace, 1,sourceBeginTime,sourceEndTime);
        //sourcePage(fixedPlace,sourceBeginTime,sourceEndTime);
    });
    //开启报警总数模态框
    $(".data .sevenDataDev .sevenDataNumCenter").on('click', function () {
        $(".data #deviceModalBox").modal('show');
        //sourceRanderListPage(fixedPlace, 1,sourceBeginTime,sourceEndTime);
        //sourcePage(fixedPlace,sourceBeginTime,sourceEndTime);
    });
    //开启报警总数模态框
    $(".data .sevenDataUntreated .sevenDataNumCenter").on('click', function () {
        $(".data #untreatedDataModalBox").modal('show');
        //sourceRanderListPage(fixedPlace, 1,sourceBeginTime,sourceEndTime);
        //sourcePage(fixedPlace,sourceBeginTime,sourceEndTime);
    });
    //---------------------------------------------------------------------------------
    //响应速度
    //$('.data #speedCanvas').on('click', function () {
    //    $('#alarmSpeedModalBox').modal('show');
    //})
    //$('.data #alarmSpeedModal-close').on('click', function () {
    //    $('#alarmSpeedModalBox').modal('hide');
    //});

})